package com.itsu.graph_v2.component;

import cn.hutool.core.math.MathUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.RandomUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.itsu.graph_v2.entity.Dept;
import com.itsu.graph_v2.entity.Result;
import com.itsu.graph_v2.service.DeptService;
import com.netflix.graphql.dgs.*;
import graphql.schema.DataFetchingEnvironment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@DgsComponent
public class DeptComponent {

    @Autowired
    DeptService deptService;

    @DgsQuery
    public List<Dept> depts(@InputArgument Integer id) {

        List<Dept> depts = deptService.findAll();

        if (ObjectUtils.isEmpty(id)) {
            return depts;
        }

        return depts.stream()
                .filter(dept -> dept.getId() == id)
                .collect(Collectors.toList());
    }


}
